package service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import dao.CategoryDao;
import entity.Category;
import service.CategoryService;

@Service
@Transactional
public class CategoryServiceImpl implements CategoryService{

	
	@Autowired
	private CategoryDao categoryDao;
	private Category category;
	
	@Transactional(readOnly=false)
	public void save(Category category){
		Category category1=new Category();
		category1.setName("测试回滚");
		CategoryDao.save(category);
	}
	
	@Transactional(readOnly=false)
	public void update1(Category category){
		categoryDao.update(category);
	}
	
	@Override
	@Transactional(readOnly=false)
	public void delete(Category category){
		categoryDao.delete(category);
	
	}
	
	@Override
	@Transactional(readOnly=false)
	public void delete(int id){
		Category category=new Category();
		category.setId(id);
		delete(category);
	}
	@Override
	@Transactional(readOnly=false)
	public void delete(int[] id) {
		for (int i : id) {
			delete(i);
		}
	}

	//查询方法定义为只读
	@Transactional(readOnly=true)
	public Category findById(int id) {
		Category user=new Category();
		category.setName("测试只读");
		CategoryDao categorytDao = null;
		CategoryDao.save(category);
		return categoryDao.findById(id);
	}

	
	@Override
	@Transactional(readOnly=true)
	public List<Category> findAll() {
		// TODO Auto-generated method stub
		return categoryDao.findAll();
	}


		
	public int countAll() {
		return categoryDao.countAll();
	}

	public List<Category> findAll1() {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public void save1(Category category) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void update(Category category) {
		// TODO Auto-generated method stub
		
	}

	public void delete1(Category category) {
		// TODO Auto-generated method stub
		
	}
	
	
 

}

